package cn.edu.zut.internship.web.controller.tutor;


import cn.edu.zut.internship.bean.sys.Result;
import cn.edu.zut.internship.bean.sys.SysUser;
import cn.edu.zut.internship.iservice.report.ReportSV;
import cn.edu.zut.internship.iservice.tutor.TutorSV;
import cn.edu.zut.internship.web.utils.UserInfoUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.poi.util.StringUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/tutor")
public class TutorController {
    @Reference
    TutorSV tutorSV;

    /**
     * 当前登录教师查询自己指导的学生列表
     * @param params
     * @return
     */
    @RequestMapping("/getMyStudent")
    public Result getMyStudent(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String teachAccount = userInfo.getUserAccount();
        params.put("teachAccount",teachAccount);
        result = tutorSV.getMyStudent(params);
        return result;
    }

    /**
     * 教师列表查询
     * @param params
     * @return
     */
    @RequestMapping("/getTeachList")
    public Result getTeachList(@RequestBody Map params) {
        Result result = new Result();
        result = tutorSV.getTeachList(params);
        return result;
    }

    /**
     * 根据教师Id列表查询指导学生列表按
     * @param params
     * @return
     */
    @RequestMapping("/getStudent")
    public Result getStudent(@RequestBody Map params) {
        Result result = new Result();
        result = tutorSV.getMyStudent(params);
        return result;
    }

    /**
     * 教师绑定要指导的学生(若入参无教师Id则使用当前登录账号Id）
     * @param params
     * @return
     */
    @RequestMapping("/choiceStudent")
    public Result choiceStudent(@RequestBody Map params) {
        Result result = new Result();
        String teachAccount = (String) params.get("teachAccount");
        if(teachAccount != null&&!teachAccount.isEmpty()){
            params.put("teachAccount",teachAccount);
        }else {
            SysUser userInfo = UserInfoUtil.getUserInfo();
            teachAccount = userInfo.getUserAccount();
            params.put("teachAccount", teachAccount);
            params.put("teachName", userInfo.getUsername());
            params.put("userInfo", userInfo);
        }
        result = tutorSV.choiceStudent(params);
        return result;
    }

    /**
     * 自动分配指导老师
     * @param params
     * @return
     */
    @RequestMapping("/autuDistribut")
    public Result autuDistribut(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("userAccount",userAccount);
        result = tutorSV.autuDistribut(params);
        return result;
    }

    /**
     * 自动分配指导教师前查询分配情况统计数据
     * @param
     * @return
     */
    @RequestMapping("/getDistributData")
    public Result getDistributData() {
        Result result = new Result();
        Map params = new HashMap();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("userAccount",userAccount);
        result = tutorSV.getDistributData(params);
        return result;
    }

    /**
     * 解除教师与学生的指导关系
     * @param params
     * @return
     */
    @RequestMapping("/noChoice")
    public Result noChoice(@RequestBody Map params) {
        Result result = new Result();
        SysUser userInfo = UserInfoUtil.getUserInfo();
        String userAccount = userInfo.getUserAccount();
        params.put("userAccount",userAccount);
        params.put("userInfo",userInfo);
        result = tutorSV.noChoice(params);
        return result;
    }
    }